<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>{{name}}</h1>
        <input type="text" v-model='name' @keydown.13='add'>
        <ul>
          <li v-for='(item,index) in ary' :key='index'>{{item}}  <button @click='del(index)'>删除</button></li>
        </ul>
    </div>
</body>
</html>
<script src="../node_modules/vue/dist/vue.js"></script>
<script>
    let t = localStorage.getItem('myary') || "[]";
    t = JSON.parse(t);
    let vm = new Vue({
        el:'#app',
        data:{
            name:"珠峰",
            ary:t
        },
        methods: {
          add(){
            this.ary.unshift(this.name)
            localStorage.setItem('myary',JSON.stringify(this.ary))
            this.name = ''
          },
          del(n){
            this.ary.splice(n,1)
            localStorage.setItem('myary',JSON.stringify(this.ary))
          }
        },
    });
</script>